//
//  MicroDetailViewController.m
//  觅影
//
//  Created by Zeus on 16/4/8.
//  Copyright © 2016年  陶虹. All rights reserved.
//

#import "MicroDetailViewController.h"
#import "MoviePlayerController.h"
#import "AppDelegate.h"

@interface MicroDetailViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;


@property (weak, nonatomic) IBOutlet UIImageView *picImageView;

@property (weak, nonatomic) IBOutlet UIView *tempView;

@property (weak, nonatomic) IBOutlet UIButton *playButton;

@property (weak, nonatomic) IBOutlet UIImageView *backImageView;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property(nonatomic, strong)NSTimer *timer;
@end

@implementation MicroDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.title = @"微影";
    self.navigationController.navigationBar.translucent = NO;
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:self.model.coverForDetail]];
    [self.backImageView sd_setImageWithURL:[NSURL URLWithString:self.model.coverBlurred]];
    self.titleLabel.text = self.model.title;
    int minute = self.model.duration / 60;
    int seconds = self.model.duration % 60;
    self.timeLabel.text = [NSString stringWithFormat:@"#%@ / %d'%d''", self.model.category, minute, seconds];
    self.contentLabel.text = self.model.myDescription;
    [self.playButton addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchUpInside];
    self.scrollView.delegate = self;
    
    
    self.picImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playAction)];
    [self.tempView addGestureRecognizer:tap];
    
    

}

- (void)viewDidAppear:(BOOL)animated
{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:9 target:self selector:@selector(animateAction) userInfo:nil repeats:YES];
    [self.timer fire];
}

#pragma mark --- 动画事件 ---
- (void)animateAction
{
    [UIView animateWithDuration:4 animations:^{
        self.scrollView.zoomScale = 1.2;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:4 animations:^{
            self.scrollView.zoomScale = 1.0;
        }];
    }];
}

#pragma mark --- scrollview允许缩放的代理方法 ---
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _picImageView;
}


#pragma mark --- 点击图片播放 ---
- (void)playAction
{
    MoviePlayerController *playerVC = [[MoviePlayerController alloc]init];
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    delegate.isFlip = YES;
    playerVC.model = self.model;
    [self presentViewController:playerVC animated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


















@end
